package calorie.com.calorie.contact;

import android.content.Context;


import com.lxh.baselibray.mvp.BasePresent;
import com.lxh.baselibray.mvp.IBaseView;
import com.lxh.baselibray.net.NetCallBack;
import com.lxh.baselibray.net.ServiceGenerator;
import com.lxh.baselibray.util.Md5Utils;
import com.lxh.baselibray.util.SPUtils;
import com.lxh.baselibray.util.ToastUtils;


import calorie.com.calorie.api.ApiService;
import calorie.com.calorie.constant.Constant;
import calorie.com.calorie.request.TransferAccountRequest;
import calorie.com.calorie.response.RealNameResponce;
import calorie.com.calorie.response.TransferAccountResponce;
import retrofit2.Call;
import retrofit2.Response;

public class TransferContact {
    public static class TransferPresent extends BasePresent<ITransferView> {
        public void transfer(Context context,String type,double tokenNum,String payPassword,String toRealName,String toAccount){
            ApiService service= ServiceGenerator.createService(ApiService.class);
            int userId= SPUtils.getInt(Constant.USER_ID,-1,context);
            TransferAccountRequest request=new TransferAccountRequest(userId,type,tokenNum, Md5Utils.stringToMD5(payPassword),toRealName,toAccount);
            service.transferAccount(request).enqueue(new NetCallBack<TransferAccountResponce>() {
                @Override
                public void onSuccess(Call<TransferAccountResponce> call, Response<TransferAccountResponce> response) {
                    if (getView()!=null){
                        getView().getTransferData(response);
                    }
                }

                @Override
                public void onFailed() {
                    //ToastUtils.showLongToast(context,"网络请求异常");
                }
            });

        }

        public void getRealNameByPhone(Context context,String account){
            ApiService service= ServiceGenerator.createService(ApiService.class);
            service.getRealName(account).enqueue(new NetCallBack<RealNameResponce>() {
                @Override
                public void onSuccess(Call<RealNameResponce> call, Response<RealNameResponce> response) {
                    if (getView()!=null){
                        getView().getRealNameByPhoneData(response);
                    }
                }

                @Override
                public void onFailed() {
                   // ToastUtils.showLongToast(context,"网络请求异常");
                }
            });

        }
    }

    public interface ITransferView extends IBaseView {
        void getTransferData(Response<TransferAccountResponce> response);
        void getRealNameByPhoneData(Response<RealNameResponce> response);
    }


}
